package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.AppMingxiChongzhiDao;
import com.vf.admin.client.dao.AppUserDao;
import com.vf.admin.client.service.AppMingxiChongzhiService;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMingxiChongzhi;
import com.vf.admin.miaodong.entity.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AppMingxiChongzhiServiceImpl implements AppMingxiChongzhiService {
    @Autowired
    private AppMingxiChongzhiDao appMingxiChongzhiDao;
  @Autowired
    private AppUserDao appUserDao;

    @Override
    public List<AppMingxiChongzhi> findList(Integer userid, SplitPageBean splitPage) {
        return appMingxiChongzhiDao.findList(userid, splitPage);
    }

    @Override
    public List<AppMingxiChongzhi> findList(Map<String, Object> params, SplitPageBean splitPage) {
        return appMingxiChongzhiDao.findList(params, splitPage);
    }

    @Override
    public List<AppMingxiChongzhi> findList1(Map<String, Object> params, SplitPageBean splitPage) {
        return appMingxiChongzhiDao.findList1(params, splitPage);
    }

    @Override
    public Double total(Map<String, Object> params) {
        BigDecimal b = BigDecimal.ZERO;
        List<AppMingxiChongzhi> total = appMingxiChongzhiDao.total(params);
        System.out.println("总数："+total.size());

        for (AppMingxiChongzhi e : total) {
            if (e.getMoney().compareTo(BigDecimal.ZERO) != 0) {
//                BigDecimal divide = e.getMoney().divide(new BigDecimal("100"));
                b = b.add(e.getMoney());
            }
        }
        return b.doubleValue();
    }

    @Override
    public BigDecimal findListSum(Map<String, Object> params) {
        BigDecimal sum = BigDecimal.ZERO;
        List<AppMingxiChongzhi> listSum = appMingxiChongzhiDao.findListSum(params);

        for (AppMingxiChongzhi e : listSum) {
            if (e.getMoney().compareTo(BigDecimal.ZERO) != 0) {
                BigDecimal divide = e.getMoney().divide(new BigDecimal("100"));
                sum = sum.add(divide);
            }
        }
        return sum;
    }

    @Override
    public AppMingxiChongzhi get(Integer id) {
        return appMingxiChongzhiDao.get(id);
    }

    @Override
    public AppMingxiChongzhi findByOrdernum(String ordernum) {
        return appMingxiChongzhiDao.findByOrdernum(ordernum);
    }

    @Override
    public AppMingxiChongzhi findByCustorderno(String custorderno) {
        return appMingxiChongzhiDao.findByCustorderno(custorderno);
    }

    @Override
    public void save(AppMingxiChongzhi haoYou) {
        appMingxiChongzhiDao.save(haoYou);
    }

    @Override
    public List<AppMingxiChongzhi> selectUserAll(Integer id) {
        return appMingxiChongzhiDao.selectUserAll(id);
    }

    @Override
    public void addMingxi(Integer userid,BigDecimal num,Integer leixing,BigDecimal money,String ordernum,String mobileSpec) {
        AppUser user=appUserDao.get(userid);
        AppMingxiChongzhi chongzhi=new AppMingxiChongzhi();
        chongzhi.setUserid(user.getId());
        chongzhi.setPic(user.getPic());
        chongzhi.setPhone(user.getLoginname());
        chongzhi.setNick(user.getNick());
        chongzhi.setLeixing(leixing);
        chongzhi.setMoney(money);
        chongzhi.setGoumainum(num);
        chongzhi.setCreatetime(new Date());
        chongzhi.setOrdernum(ordernum);
        chongzhi.setMobileSpec(mobileSpec);
        appMingxiChongzhiDao.save(chongzhi);
    }

}
